package vip.xumy.picture.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import vip.xumy.picture.pojo.Picture;

/**
 * Do not use for any commercial purposes without permission
 * 
 * @author: mengyxu
 * @date: 2021年12月31日
 */

@Mapper
public interface PictureMapper {

	@Select({ "<script>", "SELECT * FROM user_picture ", "<where>", "<if test='user != null'> AND user = #{user} </if>",
			"<if test='startTime != null'> AND time >= #{startTime} </if>",
			"<if test='endTime != null'> AND #{endTime} > time </if>",
			"<if test='remark != null'> AND remark LIKE CONCAT('%', #{remark}, '%') </if>",
			"<if test='status != null'> AND status = #{status} </if>", "</where>", "ORDER BY time DESC", "</script>" })
	List<Picture> list(Picture example);

	@Insert({ "INSERT INTO user_picture VALUES (#{id}, #{user}, NOW(), #{path}, #{space}, #{status}, #{remark})" })
	void save(Picture picture);

	@Update({ "UPDATE user_picture SET status = #{status}, remark = #{remark} WHERE id = #{id}" })
	void update(Picture picture);

	@Delete({ "DELETE FROM user_picture WHERE id = #{id}" })
	void delete(String id);

	@Delete({ "DELETE FROM user_picture WHERE user = #{user}" })
	void deleteAll(String user);

}
